home *** CD-ROM | disk | FTP | other *** search
- Path: news.halcyon.com!usenet
- From: normanb@halcyon.com (Norm Bryar)
- Newsgroups: comp.lang.c++,rb.technical
- Subject: Re: Can copy constructor and operator= share code?
- Date: Sat, 02 Mar 1996 16:08:56 GMT
- Organization: Northwest Nexus Inc.
- Message-ID: <4h9rph$1ug@news.halcyon.com>
- References: <4h2kcn$40d@rap.SanDiegoCA.ATTGIS.COM>
- NNTP-Posting-Host: blv-pm2-ip16.halcyon.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Have you tried the reverse: have copy ctor call operator=( toCopy )?
- Or *this = toCopy?
-
- --Norm
-
-
- borisb@sd.znet.com (Boris Burtin) wrote:
-
- >I have noticed that a copy constructor and operator= perform pretty
- >much the same function. The code I wrote for my class simply copies
- >each member variable from one class to the other.
-
- >Is there a way for the one of the two functions to call the other, to
- >avoid duplicate code? I have tried calling the copy constructor from
- >operator=, but nothing happens. I've gotten around this problem by
- >creating a private Copy() function, which is called by both the copy
- >constructor and operator=. Is there another way?
-
- >Thanks,
-
- >Boris
-
-
-
-
-